package com.chenglu.android.restaurant.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chenglu.android.R;
import com.chenglu.android.common.utils.LogUtils;
import com.chenglu.android.common.utils.Utils;
import com.chenglu.android.restaurant.bean.CurrentShopsInfoBean;
import com.chenglu.android.restaurant.bean.GoodscategorylisBean;

import java.util.List;

/**
 * @author: lyj
 * @Created: by Copyright 2023 3 Guangzhou Hongma Technology Co., Ltd. All rights reserved.
 * @Description：满减
 */
public class ShopCategoryAdapter extends BaseQuickAdapter<GoodscategorylisBean.DataBean, BaseViewHolder> {

    Context mContext;
    List<GoodscategorylisBean.DataBean> data;

    public ShopCategoryAdapter(Context context, @Nullable List<GoodscategorylisBean.DataBean> data) {
        super(R.layout.item_shopcategory, data);
        this.mContext = context;
        this.data = data;
    }


    @Override
    protected void convert(@NonNull BaseViewHolder helper, GoodscategorylisBean.DataBean item) {
        helper.addOnClickListener(R.id.rl_left);
        LinearLayout linearLayout = helper.getView(R.id.ll_left);
        RelativeLayout rl_left = helper.getView(R.id.rl_left);
        helper.setText(R.id.tv_item_shopcategory, item.getCategoryName());
        ImageView imageView = helper.getView(R.id.iv_item_shopcategory);
        Glide.with(mContext).load(item.getIcon()).into(imageView);
        if (item.isCheck()){
            rl_left.setBackgroundResource(R.color.white);
        }else {
            rl_left.setBackgroundResource(R.color.tranlurent);
        }

//        LogUtils.e("ShopCategoryAdapter:"+(data.size()-1));
//        LogUtils.e("getLayoutPosition:"+helper.getLayoutPosition());
        if ( helper.getLayoutPosition()==data.size()-1){
            helper.setGone(R.id.view_bottom,true);
        }else {
            helper.setGone(R.id.view_bottom,false);
        }
    }

    @Override
    public int getItemCount() {
        return getData().size();
    }
}
